<template>
  <div class="">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in banner" :key="item.id">
        <img :src="item.picUrl" alt="" />
      </van-swipe-item>
    </van-swipe>
    <div class="box">
      <my-good
        v-for="item in list"
        :key="item.id"
        :item="item"
        @click="gotoDetail(item.id)"
      ></my-good>
    </div>
  </div>
</template>

<script>
import { ref, reactive, toRefs } from "vue";
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
import { getBanner, getList } from "../utils/yx";
import myGood from "../components/myGood.vue";
export default {
  setup(props, ctx) {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    const data = reactive({
      banner: [],
      list: [],
    });
    getBanner().then((res) => {
      data.banner = res.data;
    });
    getList().then((res) => {
      console.log(res);
      data.list = res.data.slice(9, 13);
    });
    const gotoDetail = (id) => {
      router.push("/detail/" + id);
    };
    //跳转详情页

    return { ...toRefs(data), gotoDetail };
  },
  components: {
    myGood,
  },
};
</script>

<style lang="scss">
.box {
  display: flex;
  flex-wrap: wrap;
  > div {
    width: 50%;
    img {
      width: 100%;
      height: 200px;
    }
  }
}
</style>
